package com.skycode7.servlet;

import com.skycode7.bean.AdminBean;
import com.skycode7.bean.NoticeBean;
import com.skycode7.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/noticeAdd/jsp")
public class NoticeAddServlet extends HttpServlet {
    private NoticeDao noticeDao;
    protected void dopost (HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String noticeTitle = req.getParameter("NoticeTitle");
        String noticeContent = req.getParameter("NoticeContent");
        NoticeBean noticeBean =  new NoticeBean();
        noticeBean.setNoticeTitle(noticeTitle);
        noticeBean.setNoticeContent(noticeContent);
        noticeBean.setNoticeTime((new Date()).toString());
        noticeBean.setAdminName("notice");
        NoticeDao notice =new NoticeDao();
        AdminBean adminBean = null;
        NoticeBean AdminBean = null;
        int result = noticeDao.add(AdminBean);
        if(result > 0 ){
            resp.sendRedirect("noticeList/jsp");
        }else{
            req.getRequestDispatcher("WEB-INF/page/noticeAdd.jsp").forward(req,resp);
        }
    }

}
